package app.fugema.shop.main.order.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.base.common.app.LoginUtils;
import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.UIUtils;
import com.base.common.view.base.BaseTitleActivity;
import com.base.common.view.base.OnGetDataListener;
import com.base.common.viewmodel.BaseViewObserver;
import app.fugema.shop.R;
import app.fugema.shop.databinding.OrderAfterSaleListAcBinding;
import app.fugema.shop.main.order.adapter.OrderAfterSaleAdapter;
import app.fugema.shop.main.order.model.RefundOrdersResult;
import app.fugema.shop.main.order.vm.OrderAfterSaleVM;

public class OrderAfterSaleListActivity extends BaseTitleActivity<OrderAfterSaleListAcBinding, OrderAfterSaleVM> implements OnGetDataListener {

    private String userKey;

    public static void start(Context context) {
        Intent intent = new Intent(context, OrderAfterSaleListActivity.class);
        context.startActivity(intent);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order_after_sale_list_ac);
    }


    private OrderAfterSaleAdapter afterSaleAdapter;

    @Override
    protected int getStatusBarColor()
    {
        return R.color.redColor;
    }

    @Override
    protected void initView()
    {
        super.initView();
        setCloseImg(R.mipmap.ic_back_white);
        setTitle("退款/售后",R.color.white);
        afterSaleAdapter = new OrderAfterSaleAdapter();
        binding.rvRecyclerView.setAdapter(afterSaleAdapter);

        viewUtils.setRefreshStateLayout(binding.rvRecyclerView, this, this);
    }

    @Override
    protected void initData(Intent intent) {
        super.initData(intent);
        userKey = LoginUtils.getToken();

        onGetData(1);
    }

    @Override
    public void onGetData(int pn)
    {
        viewModel.refundOrderList(pn,10,userKey)
                 .observe(this, new BaseViewObserver<LiveDataWrapper<RefundOrdersResult>>(viewUtils.getStateLayout()) {
            @Override
            protected void onSuccess(LiveDataWrapper<RefundOrdersResult> data)
            {
                viewUtils.setDataListRefreshLayout(afterSaleAdapter, pn, 10, data.data.getData());
            }

            @Override
            public boolean isEmptyData(LiveDataWrapper<RefundOrdersResult> data)
            {
                //UIUtils.isEmpty(data.data.getData()) ||
                return   pn == 1 && UIUtils.isEmpty(data.data.getData() );
            }

            @Override
            public boolean isRefreshLayoutData() {
                return true;
            }

            @Override
            protected void onComplete() {
                super.onComplete();
                viewUtils.stopRefreshLayout();
            }
        });
    }


}
